/*
https://leetcode-cn.com/problems/decode-xored-permutation/solution/jie-ma-yi-huo-hou-de-pai-lie-by-leetcode-9gw4/
 */
import java.util.Arrays;

public class Solution1734 {
    public int[] decode(int[] encoded) {
        int n=encoded.length+1;
        int t=0;
        for (int i=1;i<=n;i++){
            t=t^i;
        }
        for (int i=1;i<encoded.length;i+=2){
            t=t^encoded[i];
        }
        int[] ans=new int[encoded.length+1];
        ans[0]=t;
        for (int i=0;i<encoded.length;i++){
            ans[i+1]=ans[i]^encoded[i];
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(new Solution1734().decode(new int[]{3,1})));
    }
}
